﻿package commands 
{
	import flash.utils.ByteArray;
	import commands.classesinfo.*;
	
	/**
	 * ...
	 * @author wwx
	 * 10000001 登录
	 */
	public class LoginCmdReq extends abCommand
	{
		
		public function LoginCmdReq() //: abCommand(CommandType.CMD_TYPE_LOGIN_REQ)
		{
			super(CommandType(CommandType.CMD_TYPE_LOGIN_REQ));
			userName = "";
			passWord = "";
			msgSeq = 10000001;
		}
		
		private var msgSeq:int;//消息号
		public var reserve:int;//保留字段
		
		public var userName:String;//账号
		public var passWord:String;//密码
		
		public var roleId:int;//用户ID。
		
		public function convertToBytes(bytes:ByteArray, offset:int):int
		{

			var len:int = 0;
			len += offset;
			bytes[offset + 0] = (msgSeq & 0xff);
			bytes[offset + 1] = ((msgSeq >> 8) & 0xff);
			bytes[offset + 2] = ((msgSeq >> 16) & 0xff);
			bytes[offset + 3] = ((msgSeq >> 24) & 0xff);
			len += 4;
			offset += 4;	
			bytes.position = offset;
			bytes[offset + 0] = (reserve & 0xff);
			bytes[offset + 1] = ((reserve >> 8) & 0xff);
			bytes[offset + 2] = ((reserve >> 16) & 0xff);
			bytes[offset + 3] = ((reserve >> 24) & 0xff);			
			len += 4;
			offset += 4;
			bytes.position = offset;

			//bytes.writeShort(userName.length);
			bytes[offset + 0] = (userName.length & 0xff);
			bytes[offset + 1] = ((userName.length >> 8) & 0xff);		
			len += 2;
			offset += 2;
			bytes.position = offset;
			bytes.writeMultiByte(userName, "gb2312");
			len += userName.length;
			offset += userName.length;
			bytes.position = offset;
			//bytes.writeShort(passWord.length);
			bytes[offset + 0] = (passWord.length & 0xff);
			bytes[offset + 1] = ((passWord.length >> 8) & 0xff);			
			len += 2;
			offset += 2;
			bytes.position = offset;
			bytes.writeMultiByte(passWord, "gb2312");
			len += passWord.length;
			offset += passWord.length;
			
			bytes[offset + 0] = (roleId & 0xff);
			bytes[offset + 1] = ((roleId >> 8) & 0xff);
			bytes[offset + 2] = ((roleId >> 16) & 0xff);
			bytes[offset + 3] = ((roleId >> 24) & 0xff);			
			len += 4;
			offset += 4;
			
			bytes.position = offset;
			bytes.length = offset;
			return len;
		}
	}
	
}